package com.ktc.search.service;

import com.ktc.search.dao.ArticleDao;
import com.ktc.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import util.IdWorker;

/**
 * @author lscl
 * @version 1.0
 * @intro:
 */
@Service
public class ArticleService {

    @Autowired
    private ArticleDao articleDao;

    @Autowired
    private IdWorker idWorker;

    public void save(Article article){

        article.setId(idWorker.nextId()+"");

        articleDao.save(article);
    }

    /**
     * 搜索
     *  不仅要搜索title还要content
     * @param keywords
     * @param page
     * @param size
     * @return
     */
    public Page<Article> search(String keywords, Integer page, Integer size) {

        return  articleDao.findByTitleLikeOrContentLike(keywords,keywords, PageRequest.of(page-1,size));

    }
}
